package web.action;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;

import web.handle.CityPropertiesBean;

import ejb.entity.User;
import ejb.manager.PositionManager;
import ejb.manager.UserManager;

@ManagedBean
public class CityPropertiesAction {
	@EJB
	private PositionManager positionManager;
	@EJB
	private UserManager userManager;
	
	@ManagedProperty(value="#{cityPropertiesBean}")
	private CityPropertiesBean cityPropertiesBean;
	
	public CityPropertiesAction(){}
	
	public CityPropertiesBean getCityPropertiesBean() {
		return cityPropertiesBean;
	}

	public void setCityPropertiesBean(CityPropertiesBean cityPropertiesBean) {
		this.cityPropertiesBean = cityPropertiesBean;
	}

	public String addPosition(){
		String login = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
		User currentuser = userManager.getUserByLogin(login);
		positionManager.addPosition(this.getCityPropertiesBean().getPositionName(), currentuser, this.getCityPropertiesBean().getX(), this.getCityPropertiesBean().getY());
		return "selfclose";
	}
	
}
